<!DOCTYPE html>
<html class="x-admin-sm">
{include file='public/header'}
<script src="/admin/xadmin/lib/layui/upload.js" charset="utf-8"></script>

<body>
    <div class="x-body">
        <form class="layui-form" lay-filter="formAjax">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>用户名
                </label>
                <div class="layui-input-block">
                    <input type="text" name="name" id="name" placeholder="用户名" required="required"
                        lay-verify="required" autocomplete="off" class="layui-input" value="" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>角色
                </label>
                <div id="pMenu" style="width:100%;flex:1"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    合作公司
                </label>
                <div id="pCompany" style="width:100%;flex:1"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    版权方
                </label>
                <div id="pCoOperative" style="width:100%;flex:1"></div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>头像
                </label>
                <button type="button" class="layui-btn" id="video_btn">上传</button>
                <div class="layui-upload-list" style="display: none;margin-left: 110px;">
                    <img onclick="showimg(this)" class="layui-upload-img" style="width: 100px;">
                </div>
                <input type="hidden" name="profile_photo" id="profile_photo" value="" />
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>密码
                </label>
                <div class="layui-input-block">
                    <input type="password" name="password" id="password" placeholder="密码" required="required"
                        lay-verify="required" autocomplete="off" class="layui-input" value="" />
                    <div class="layui-form-mid layui-word-aux layui-font-red">请慎重修改！！！</div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <span class="x-red">*</span>介绍
                </label>
                <div class="layui-input-block">
                    <textarea name="introduce" id="introduce" placeholder="介绍" required="required"
                        lay-verify="required" autocomplete="off" class="layui-textarea" value="" ></textarea>
                </div>
            </div>     

            <input type="hidden" name="id" id="id" value="" />
            <button id="submitData" class="layui-btn" lay-submit lay-filter="submitData" style="display: none;" />
        </form>
    </div>
    <script>
        let params = {
            addUrl: '/admin/admin/add',
            editUrl: '/admin/admin/edit',
            detailUrl: '/admin/admin/detail',
        }
        form_ajax(params)
        let id = GetQueryString('id')
        let selectParams = {
            url: '/admin/rule/select',
            selected: [],
            tips: '选择角色',
            name: 'rule_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pMenu'
        }

        let selectParams1 = {
            url: '/admin/company/select?type=1',
            selected: [],
            tips: '选择公司',
            name: 'company_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pCompany'
        }

        let selectParams2 = {
            url: '/admin/partners/selectList',
            selected: [],
            tips: '选择版权方',
            name: 'partner_id',
            field_id: 'id',
            field_Name: 'name',
            elem: '#pCoOperative'
        }
        

        if (id) {
            Ajax(params.detailUrl, { id }).then(result => {
                selectParams.selected = [result.data.rule_id]
                selectN(selectParams)
                selectParams2.selected = [result.data.partner_id]
                selectN(selectParams2)
                selectParams1.selected = [result.data.company_id]
                selectN(selectParams1)
                if(result.data.profile_photo){
                    $('.layui-upload-list').show()
                    $('.layui-upload-img').attr('src', result.data.profile_photo);
                    $("input[name='profile_photo']").val(result.data.profile_photo);
                }
            });
        } else {
            selectN(selectParams)
            selectN(selectParams1)
            selectN(selectParams2)
        }


        uploadFile({
            elem: '#video_btn', 
            ossUrl:'/admin/video/uploadCredentials',
            uploadSuccessCallback: function (res) {
                $('.layui-upload-list').show()
                $('.layui-upload-img').attr('src', res.url);
                $("input[name='profile_photo']").val(res.url);
            }, 
            uploadErrorCallback: function() {
                return layer.msg('上传失败');
            }
        })
    </script>
</body>

</html>